package com.one.shopping.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.one.shopping.R;
import com.one.shopping.ui.fragment.GoodsItemFragment;
import com.one.shopping.ui.fragment.MemberItemFragment;
import com.one.shopping.ui.fragment.OrdersItemFragment;
import com.one.shopping.ui.fragment.UsersItemFragment;

import static com.one.shopping.util.Constant.SWITCH_GOODS_MANAGE_CODE;
import static com.one.shopping.util.Constant.SWITCH_MANAGE_CODE;
import static com.one.shopping.util.Constant.SWITCH_MEMBER_MANAGE_CODE;
import static com.one.shopping.util.Constant.SWITCH_ORDERS_MANAGE_CODE;
import static com.one.shopping.util.Constant.SWITCH_USER_MANAGE_CODE;

/**
 * @author 柯尊诚
 * @version 1.0
 * @date 创建时间：2016/1/12 08:27
 */
public class AdminDetailFragmentActivity extends FragmentActivity{

    private FragmentTransaction transaction;
    private TextView titleValues;
    private ImageView addBtn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_admin_detail);
        transaction = getSupportFragmentManager().beginTransaction();

        titleValues = (TextView) findViewById(R.id.main_title_tv);
        initView();

    }

    private void initView() {
        addBtn = (ImageView) findViewById(R.id.main_add_btn_iv);
        addBtn.setVisibility(View.VISIBLE);

        switch (SWITCH_MANAGE_CODE) {
            case SWITCH_USER_MANAGE_CODE :
                UsersItemFragment usersItemFragment = new UsersItemFragment();
                transaction.replace(R.id.fragment_container, usersItemFragment).commit();
                titleValues.setText("收银员管理");
                addBtn.setOnClickListener(onClickAddUserBtnListener);
                break;

            case SWITCH_MEMBER_MANAGE_CODE :
                MemberItemFragment memberItemFragment = new MemberItemFragment();
                transaction.replace(R.id.fragment_container, memberItemFragment).commit();
                titleValues.setText("会员管理");
                addBtn.setOnClickListener(onClickAddMemberBtnListener);
                break;

            case SWITCH_GOODS_MANAGE_CODE :
                GoodsItemFragment goodsItemFragment = new GoodsItemFragment();
                transaction.replace(R.id.fragment_container, goodsItemFragment).commit();
                titleValues.setText("商品管理");
                addBtn.setOnClickListener(onClickAddGoodsBtnListener);
                break;
            case SWITCH_ORDERS_MANAGE_CODE :
                OrdersItemFragment ordersItemFragment = new OrdersItemFragment();
                transaction.replace(R.id.fragment_container, ordersItemFragment).commit();
                titleValues.setText("订单查询");
                break;
        }
    }

    /**
     * 点击添加按钮
     */
    private View.OnClickListener onClickAddUserBtnListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
            Intent intent = new Intent(AdminDetailFragmentActivity.this, AddUserActivity.class);
            startActivity(intent);
        }
    };

    /**
     * 点击添加按钮
     */
    private View.OnClickListener onClickAddMemberBtnListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
            Intent intent = new Intent(AdminDetailFragmentActivity.this, AddMemberActivity.class);
            startActivity(intent);
        }
    };

    /**
     * 点击添加按钮
     */
    private View.OnClickListener onClickAddGoodsBtnListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
            Intent intent = new Intent(AdminDetailFragmentActivity.this, AddGoodsActivity.class);
            startActivity(intent);
        }
    };
}
